package com.alibaba.yinan.domain.task.service.policy;

import com.alibaba.cola.extension.BizScenario;
import com.alibaba.yinan.domain.common.extension.ExtensionBasedSelector;
import com.alibaba.yinan.domain.task.service.policy.extensionpoint.DispatchPolicyExtPt;
import com.alibaba.yinan.domain.task.Task;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName DispatchPolicySelector
 * @Author mengke
 * @create 2025/8/3 22:23
 * @Description
 */
@Slf4j
@Component
public class DispatchPolicySelector {

    @Resource
    private ExtensionBasedSelector selector;

    public String selectDevice(Task task, List<String> policyKeys) {
        log.info("taskId:{} , policyKeys:{} ", task, policyKeys);
        return selector.executeFirstSupported(
                DispatchPolicyExtPt.class,
                policyKeys,
                BizScenario.valueOf("task", "assign", task.getType().name().toLowerCase()),
                (ext, key) -> ext.support(key) ? ext.selectDevice(task) : null
        );
    }
}
